<?php
namespace app\index\controller;
use think\Controller;
use think\Db;
use think\Session;
class Collect extends Controller{
    /****
     Class register     商品收藏
     *@
    */  
    public function collect_shop(){
        $post = input('post.');
        $collect_goods = Db::name('collect_goods')->where(['user_id'=>$post['user_id'],'goods_id'=>$post['goods_id']])->find();
        if($collect_goods){
           $arr = [
               'state'     		=> 1,
			   'collect_goods'	=>$collect_goods,
               'message'   		=> "请求成功(已收藏)"
            ]; 
            return json($arr);
        }else{
			$arr = [
               'state'     => 0,
               'message'   => "请求成功(未收藏)"
            ]; 
            return json($arr);
		}
    }
    public function collect_shop_add(){
        $post = input('post.');
		if($post['type_form'] == 'delete'){
			$goods_id = input('goods_id');
			$user_id = input('user_id');
			$collect_goods_add = Db::name('collect_goods')->where(['goods_id'=>$goods_id,'user_id'=>$user_id])->delete();
			if($collect_goods_add){
			   $arr = [
				   'state'     => 1,
				   'message'   => "请求成功"
				]; 
			}else{
				$arr = [
				   'state'     => 0,
				   'message'   => "请求失败"
				]; 
			}
			return json($arr);
		}
        $data = [
          'user_id'   =>$post['user_id'],
          'goods_id'  =>$post['goods_id'],
          'addtime'   =>time()
        ];
        $collect_goods_add = Db::name('collect_goods')->insert($data);
        if($collect_goods_add){
           $arr = [
               'state'     => 1,
               'message'   => "请求成功"
            ]; 
        }else{
            $arr = [
               'state'     => 0,
               'message'   => "请求失败"
            ]; 
        }
        return json($arr);
    }

    /****
     Class register     商家收藏
     *@
    */
    public function collect_manystore(){
       $post = input('post.');
        $collect_manystore = Db::name('collect_manystore')->where(['user_id'=>$post['user_id'],'manystore_id'=>$post['manystore_id']])->find();
        if($collect_manystore){
           $arr = [
               'state'     => 1,
               'message'   => "请求成功"
            ]; 
            return json($arr);
        }else{
			$arr = [
               'state'     => 0,
               'message'   => "请求成功(未收藏)"
            ]; 
            return json($arr);
		}
    }
    

    
    public function collect_manystore_add(){
        $post = input('post.');
		if($post['type_form'] == 'delete'){
			$manystore_id = input('manystore_id');
			$user_id = input('user_id');
			$collect_goods_add = Db::name('collect_manystore')->where(['manystore_id'=>$manystore_id,'user_id'=>$user_id])->delete();
			if($collect_goods_add){
			   $arr = [
				   'state'     => 1,
				   'message'   => "请求成功"
				]; 
			}else{
				$arr = [
				   'state'     => 0,
				   'message'   => "请求失败"
				]; 
			}
			return json($arr);
		}
        $data = [
          'user_id'   =>$post['user_id'],
          'manystore_id'  =>$post['manystore_id'],
          'addtime'   =>time()
        ];
        $collect_manystore_add = Db::name('collect_manystore')->insert($data);
        if($collect_manystore_add){
           $arr = [
               'state'     => 1,
               'message'   => "请求成功"
            ]; 
        }else{
            $arr = [
               'state'     => 0,
               'message'   => "请求失败"
            ]; 
        }
        return json($arr);
    }
    
    
}